package com.hex.liyue.launchdatemodule.presenter;

import com.hex.liyue.commonmodule.bean.BaseBean;
import com.hex.liyue.commonmodule.manager.HttpManager;
import com.hex.liyue.commonmodule.manager.UserManager;
import com.hex.liyue.commonmodule.net.ResponseListener;
import com.hex.liyue.lookingdatemodule.bean.AppointmentDetailsResultBean;

/**
 * Created by WJ on 2016/6/25.
 */
public class LaunchDetailsPresenter {
    private ILaunchDetailsView iLaunchDetailsView;

    public LaunchDetailsPresenter(ILaunchDetailsView iLaunchDetailsView) {
        this.iLaunchDetailsView = iLaunchDetailsView;
    }

    /**
     * 获取我发起的约会的详情
     *
     * @param appointment_id
     */
    public void requestDetails(String appointment_id) {
        iLaunchDetailsView.showLod("加载中...");
        HttpManager.getInstance().findAppointmentDetails(UserManager.getUserId(), appointment_id, new ResponseListener<AppointmentDetailsResultBean>() {
            @Override
            public void onSuccess(AppointmentDetailsResultBean appointmentDetailsResultBean) {
                iLaunchDetailsView.closeLod();
                iLaunchDetailsView.setAdapter(appointmentDetailsResultBean);
            }

            @Override
            public void onFailure(String responseresult) {
                iLaunchDetailsView.closeLod();
                iLaunchDetailsView.showT(responseresult);
            }
        });
    }

    /**
     * 同意应约人约会
     */
    public void accept(String apply_uid, String accept_id,final String appointment_id) {
        iLaunchDetailsView.showLod("加载中...");
        HttpManager.getInstance().accept(UserManager.getUserId(), apply_uid, accept_id, new ResponseListener<BaseBean>() {
            @Override
            public void onSuccess(BaseBean baseBean) {
                iLaunchDetailsView.closeLod();
                requestDetails(appointment_id);
            }

            @Override
            public void onFailure(String responseresult) {
                iLaunchDetailsView.closeLod();
                iLaunchDetailsView.showT(responseresult);
            }
        });
    }

    /**
     * 拒绝应约人约会
     *
     * @param accept_id
     * @param appointment_id
     */
    public void reject(String accept_id, final String appointment_id) {
        iLaunchDetailsView.showLod("加载中...");
        HttpManager.getInstance().reject(UserManager.getUserId(), accept_id, appointment_id, new ResponseListener<BaseBean>() {
            @Override
            public void onSuccess(BaseBean baseBean) {
                iLaunchDetailsView.closeLod();
                requestDetails(appointment_id);
            }

            @Override
            public void onFailure(String responseresult) {
                iLaunchDetailsView.closeLod();
                iLaunchDetailsView.showT(responseresult);
            }
        });
    }
}
